package fr.xebia.batch;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.batch.item.ItemProcessor;

public class MailProcessor implements ItemProcessor<Xebian, Xebian> {

	public Xebian process(Xebian p) throws Exception {
		Xebian xebian = p;
		addEmail(xebian);
		
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
		
		Date date = sdf.parse(xebian.getDate_entree());
		if(date.after(new Date())){
			xebian = null;
		}
		
		return xebian;
	}

	private void addEmail(Xebian xebian) {
		String mail = xebian.getPrenom().substring(0, 1)+xebian.getNom()+"@xebia.fr";
		xebian.setMail(mail);
	}

}
